#include <stdio.h>
#include "DoubleList.h"
#include "TpDetec.h"
#include "BmpShow.h"
#include "SwitchAreaFunc.h"

extern int old_x;
extern int new_x;
extern int new_y;	
extern int valid;

extern DNodep Headp;
extern DNodep Tempp;

int film_flag = 0;


static void ChangePic(int mode);


void* SwitchAreaDect(void * arg)
{
    //0. 探测手指位置，如果在最右边附近，那么显示侧边栏
    //1. 显示侧边栏：包括选项上一张、下一张、幻灯片等等
    lcd_showbmp_api(MENU_PIC, 730, 0,0);
    //2. 检测触摸屏按下的位置，得到响应的选项，执行对应的动作
    for(;;)
    {
        if(valid == 0)
        {
            continue;
        }
        else 
        {
            valid = 0;
        }
        if(new_x > 730)
        {
			int selcase= new_y/60;  //every block is 60 height
			printf("Selcase = %d\n", selcase);
			switch(selcase)
			{
				case 0://new_y [420, 480]  上一张
					ChangePic(0);
					break;
				case 1://new_y [360, 420] 下一张 
					ChangePic(1);
					break;
				case 4:
					film_flag = 1;
					break;
				case 7:
					film_flag = 0;
					break;
				default:
					break;
			}
        }//if(new_x > 730)

    }

}


static void ChangePic(int mode)
{
	if(mode == 0)
	{
	 //如果前面还有照片
	   	if(Tempp->prev != Headp)
		{ 
			Tempp = Tempp->prev;
		}
		else//如果前面没有照片了(Tempp->prev == Headp),重头开始
		{
		  Tempp = Headp->prev;   //skip Headp
		}
	}
	else
	{
		//如果后面还有照片
		if(Tempp->next != Headp)
		{ 
			Tempp = Tempp->next;
		}
		else//如果后面没有照片了(Tempp->next == Headp),重头开始
		{
		  Tempp = Headp->next;   //skip Headp
		}
	}
	lcd_showbmp_api(Tempp->data, 0,0, 1);
	lcd_showbmp_api(MENU_PIC, 730, 0,0);
}
